﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using npunkliner.lib;

namespace npunkliner.app
{
    class Program
    {
        static Dictionary<string, bool> hosts;

        static void Main(string[] args)
        {
            var smbListener = new SambaListener();
            smbListener.HostStatusUpdate += new EventHandler<HostStatusUpdateEventArgs>(smbListener_HostStatusUpdate);
            hosts = new Dictionary<string, bool>();

            smbListener.Run();
            System.Threading.Thread.Sleep(10000);
            smbListener.Stop();
            Console.WriteLine("Host\t\tStatus");
            Dictionary<bool, string> onlineStatusStr = new Dictionary<bool, string>();
            onlineStatusStr[true] = "online";
            onlineStatusStr[false] = "offline";

            foreach (var de in hosts)
            {
                Console.WriteLine("{0}\t\t{1}", de.Key, onlineStatusStr[de.Value]);
            }

            Console.ReadKey();
        }

        static void smbListener_HostStatusUpdate(object sender, HostStatusUpdateEventArgs e)
        {
            var packetInfo = e.PacketInfo;
            var date = e.UpdateDate;

            Console.WriteLine(packetInfo.EndPoint.ToString() + " " + packetInfo.HostName + " " + date + " is online " +
                   packetInfo.IsOnline.ToString());

            hosts[e.PacketInfo.HostName] = e.PacketInfo.IsOnline;
        }
    }
}
